import socket


def main():
    tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    dest_ip = input('请输入服务器IP地址：')
    dest_port = int(input('请输入服务器端口号：'))
    tcp_socket.connect((dest_ip, dest_port))

    download_file_name = input('请输入要下载的文件名：')
    tcp_socket.send(download_file_name.encode('utf-8'))

    # 接受的数据
    data = tcp_socket.recv(1024*1024)
    if data:
        with open('new_'+download_file_name, 'wb') as f:
            f.write(data)
        print('下载成功！')
    tcp_socket.close()


if __name__ == '__main__':
    main()
